package com.watereast;

import com.alibaba.fastjson.JSONObject;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

public class TestJM {
    public static void main(String[] args) {
        String file = "C:\\Users\\nietao-002\\Downloads\\JMQ.csv";
        List<UserInfoPoJo> userInfoPoJos = ReadCSV.readCSV(file);
        List<JSONObject> jsonObjectList = null;
        if (userInfoPoJos.size() != 0) {
            JSONObject jsonObject = null;
            jsonObjectList = new ArrayList<>();
            for (UserInfoPoJo userInfoPoJo : userInfoPoJos) {
                String openid = userInfoPoJo.getOpenid();
                String pid = userInfoPoJo.getPid();
                String phone = userInfoPoJo.getPhone();
                String validAesKey = "Kk1rR5v3OeeHDf9q";
                String encryptOpenid = DigestUtil2.encryptAES(openid, validAesKey, true);
                String encryptPid = DigestUtil2.encryptAES(pid, validAesKey, true);
                String encryptPhone = DigestUtil2.encryptAES(phone, validAesKey, true);
                ValidFailedUserInfoVo validFailedUserInfoVo = new ValidFailedUserInfoVo();
                validFailedUserInfoVo.setEncryptOpenid(encryptOpenid);
                validFailedUserInfoVo.setEncryptPhone(encryptPhone);
                validFailedUserInfoVo.setEncryptPid(encryptPid);
                jsonObject = (JSONObject)JSONObject.toJSON(validFailedUserInfoVo);
                jsonObjectList.add(jsonObject);
            }
            String fileName = "C:\\Users\\nietao-002\\Desktop\\output.txt";
            PrintStream console = System.out;
            FileOutputStream fileOutputStream = null;
            try {
                fileOutputStream = new FileOutputStream(fileName);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            PrintStream printStream = new PrintStream(fileOutputStream);
            System.setOut(printStream);
            for (JSONObject object : jsonObjectList)
                System.out.println(object);
            System.setOut(console);
            System.out.println(");
        }
    }
}
